

def singleton(class_):
    instances = {}

    def getInstance(makeNew=False, *args, **kwargs):
        if class_ not in instances or makeNew:
            instances[class_] = class_(*args, **kwargs)
        return instances[class_]
    return getInstance

